package cn.jiahua.hospital.controller;

import cn.jiahua.hospital.constants.ResultEnum;
import cn.jiahua.hospital.dto.DoctorScheduleDto;
import cn.jiahua.hospital.dto.Result;
import cn.jiahua.hospital.service.ScheduleService;
import cn.jiahua.hospital.utils.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Api
@RestController
@RequestMapping("api/schedule")
public class ScheduleController {

    @Resource
    ScheduleService scheduleService;

    @GetMapping("getDoctorschedule")
    @ApiImplicitParam(name = "doctorId",value = "医生id")
    @ApiOperation(value="获取医生的排版信息",notes = "医生页面的排版信息，根据医生编号获取")
    public Result getDoctorschedule(Integer doctorId){
        List<DoctorScheduleDto> doctorSchedule = null;
        if (doctorId == null || doctorId == null) {
            return ResultUtils.returnFail(ResultEnum.FAIL_PARAM.getCode(), ResultEnum.FAIL_PARAM.getMsg());
        }
        try {
            doctorSchedule = scheduleService.getDoctorSchedule(doctorId);
            if (doctorSchedule == null || doctorSchedule.size() <= 0) {
                return ResultUtils.returnFail(ResultEnum.FAIL_HAVE_NOT_EXIST.getCode(), ResultEnum.FAIL_HAVE_NOT_EXIST.getMsg());
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return  ResultUtils.returnDataSuccess(doctorSchedule);
    }

//    public static void main(String[] args) {
//        //获取至今日起的一个星期的日期信息，将这些信息封装到dto中
//        Date date = new Date();
//
//        //封装今天的日期信息，当天的日期信息中没有预约号
//        SimpleDateFormat formatter = new SimpleDateFormat("MM-dd");
//
//        //设置后面几天的日期信息
//        Calendar calendar = Calendar.getInstance();
//        calendar.setTime(date);
//
//        //设置今天起后面七天的日期信息
//        for (int i=1;i<=6;i++){
//            //把日期往后增加一天.整数往后推,负数往前移动
//            calendar.add(calendar.DATE,1);
//            //这个时间就是日期往后推一天的结果
//            date=calendar.getTime();
//            String tomorrowStr = formatter.format(date);
//            System.out.println(tomorrowStr);
//
//        }
//    }

}
